﻿using System;
using AB.ServiceDirectory.Commons.DataFilters;

namespace AB.ServiceDirectory.Design.Directorates
{
    public partial class DirectorateList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ViewState["filter"] = new DirectorateFilter(); ;
            }
        }

        protected void CheckBoxInactive_CheckedChanged(object sender, EventArgs e)
        {
            var filter = ViewState["filter"] as DirectorateFilter;
            if (filter != null)
            {
                filter.IncludeInactive = CheckBoxInactive.Checked;
                GridViewDirectorate.DataBind();
            }
        }

        protected void FilterByLetters_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            var filter = ViewState["filter"] as DirectorateFilter;
            if (filter != null)
            {
                var beginningLetters = StringTools.GetLetterGroup(e.CommandName);
                filter.SetBeginningLetters(beginningLetters);
                this.GridViewDirectorate.DataBind();
                this.GridViewDirectorate.PageIndex = 0;
            }
        }

        protected void ObjectDataSourceDirectorate_Selecting(object sender, System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e)
        {
            var filter = ViewState["filter"] as DirectorateFilter;
            if (filter != null)
            {
                e.InputParameters["filter"] = filter;
                filter.OrganizationId = 11;
            }
        }

        protected void LinkButtonCreate_Click(object sender, EventArgs e)
        {
            Response.Redirect("DirectorateDetails.aspx");
        }
    }
}